package com.example.newbiechen.ireader.service.boluoxs;

import android.util.Log;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by robrk on 2019/3/10.
 */

public class HtmlBookDownloader {
    public void getPageByUrl(String urlPath){
        String url = "https://m.boluoxs.com" + urlPath;
        OkHttpClient okHttpClient = new OkHttpClient();
        final Request request = new Request.Builder()
                .url(url)
                .get()//默认就是GET请求，可以不写
                .build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.d("OkHttpClient", "onFailure: ");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                byte[] b = response.body().bytes(); //获取数据的bytes
                String info = new String(b, "GBK"); //然后将其转为gbk

                Log.d("OkHttpClient", "onResponse: " + info);
            }
        });
    }
}
